package 力扣日常刷题.木22二月.第11天217;

/**
 * @author 帅小伙
 * @date 2022/2/17
 * @description
 */
public class Demo81二分查找 {

    public int search(int[] nums, int target) {
        int l = 0, r = nums.length - 1;
        while (l < r) {
            int mid = (r + l) / 2;
            if(nums[mid] == target) return mid;
            if(nums[mid] > target)r = mid;
            else l = mid +1;
        }
        return nums[r] == target ? r :-1;

    }


}
